<template>
  <view class="table-body">
    <view class="parent-row">
      <view class="col name">{{ item.shopName }}</view>
      <view class="col">{{ item.quantity }}</view>
      <view class="col">0</view>
      <view class="col">∞</view>
    </view>
  </view>
</template>
<script>
import UniIcons from "../../../uni_modules/uni-icons/components/uni-icons/uni-icons.vue";
import _ from "lodash";
import SMS from "../../functional/popup/SMS.vue";
import {getAction} from "../../../utils/action";
import UniLoadMore from "../../../uni_modules/uni-load-more/components/uni-load-more/uni-load-more.vue";

export default {
  name: "detailListView",
  components: {UniLoadMore, SMS, UniIcons},
  props: {
    item: Object,
  },
  data() {
    return {
      childList: [], // 第二级
      dowList: [], //最底级
      expanded: false,
      childExpanded: false,
      loadingStatus: 'more',
      url: {
        shopInventoryList: "api/boss/shopInventoryPageList"
      }
    }
  },
  mounted() {
    this.expanded = this.item.expanded
    this.childList = _.cloneDeep(this.item.childrenList)
    if(this.childList){
      this.childList = this.childList.map(item => ({...item, childExpanded: false}))
    }
  },
  methods: {
    // 切换展开状态
    toggleExpand() {
      this.$set(this, 'expanded', !this.expanded); // 只需这一行
    },
    //子项展开状态
    async openChildExpand(child) {
      this.loadingStatus = "loading";
      this.childList = this.childList.map(item => {
        if (item.specsId === child.specsId) {
          return {...item, expanded: !item.expanded}
        }
        return {...item, expanded: false} // 确保单层展开
      })
      let res = await getAction(this.url.shopInventoryList, {specsId: child.specsId})
      if (res.success) {
        this.dowList = res.result
      }
      this.$nextTick(() => {
        this.loadingStatus = 'noMore';
      })
    },
  }
}
</script>
<style scoped lang="scss">
.parent-row {
  background-color: #fff;
  display: grid;
  grid-template-columns: 2fr 1fr 1fr 0.8fr;
  align-items: center;
  padding: 25rpx 0;
  border-bottom: 1rpx solid #eee;
}

.child-row {
  border-bottom: 1rpx solid #eee;

  &::before {
    content: "";
    position: absolute;
    left: 20rpx;
    top: 50%;
    width: 15rpx;
    height: 1px;
  }

  .child-row-click {
    height: 75rpx;
    grid-template-columns: 2fr 1fr 1fr 0.8fr;
    display: grid;
    align-items: center;
    position: relative;
  }
}

.grandchild-row {
  padding-left: 80rpx; // 三级缩进
  border-top: 1rpx solid #eee;

  .grandchild-row-click {
    height: 75rpx;
    grid-template-columns: 2fr 1fr 1fr 0.8fr;
    display: grid;
    align-items: center;
    position: relative;
  }
}

.col {
  flex: 1;
  text-align: center;
  font-size: 22rpx;
  color: #333;
}

.name {
  text-align: left !important;
  padding-left: 40rpx;
}

.child-row .name {
  padding-left: 80rpx;
}

.action {
  display: flex;
  justify-content: center;
}

</style>
